<?php
session_start();

require_once '../include/common.inc.php';

$userinfo=$db->fetch_row($db->query("select m.*,ms.* from {$tablepre}members m,{$tablepre}memberfields ms  where m.uid=ms.uid and m.uid='{$uid}'"));

switch($act){
    // 获取软件过来的链接，验证token有效存在则注册后登录 Author @liuhuiwu<13750088090@sina.cn>
    // 注意ie浏览器不支持此格式跳转
    // {exit("<script>top.location.reload(true);location.href='./';</script>");}
    case "rename":
        $is_update= true;
        if(strlen($nickname) <= 0){
            echo "<script>alert('请输入昵称');location.href='/room/rename.php?uid={$uid}';</script>";
            $is_update= false;
        }

//        if(strlen($nickname) > 11){
//            echo "<script>alert('昵称不能超过十一个字符');location.href='/room/rename.php?uid={$uid}';</script>";
//            $is_update= false;
//        }

        if($nickname  == $userinfo['nickname']){
            echo "<script>alert('与账户名称相同,请重新修改');location.href='/room/rename.php?uid={$uid}';</script>";
            $is_update= false;
        }


        $renickname=$db->fetch_row($db->query("select m.*,ms.* from {$tablepre}members m,{$tablepre}memberfields ms  where m.uid=ms.uid and ms.nickname='{$nickname}'"));
        if($renickname){
            $is_update= false;
            echo "<script>alert('昵称已存在');location.href='/room/rename.php?uid={$uid}';</script>";
        }

        function replaceSpecialChar($nickname){
            $regex = "/\/|\~|\!|\@|\#|\\$|\%|\^|\&|\*|\(|\)|\_|\+|\{|\}|\:|\<|\>|\?|\[|\]|\,|\.|\/|\;|\'|\`|\-|\=|\\\|\|/";
            return preg_replace($regex,"",$nickname);
        }
        $nickname = replaceSpecialChar($nickname);


        if($is_update){

            $db->query("update {$tablepre}memberfields set  nickname='$nickname' where uid='$uid'");
//            echo "<script>top.alertAD();</script>";
            echo "<script> top.My.nick='$nickname';top.layer.closeAll();</script>";
        }
        break;
}


?>
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title><?=$cfg['config']['title']?> </title>
    <meta name="viewport" content="width=device-width,height=device-height,initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-capable" content="default">
    <link href="images/minilogin.css" rel="stylesheet" type="text/css"  />
    <script src="script/jquery.min.js"></script>
    <script src="script/layer.js"></script>
</head>
<body>


<img border='0' src='images/renameBg.jpg' width='100%' height='100%' style='position: absolute; z-index: -1;margin:0px;padding:0px'>

<div class="login">

    <div class="header">
        <div class="switch" id="switch">
            <!--                <a class="switch_btn_focus" id="switch_qlogin" href="javascript:void(0);" tabindex="7">快速登录</a>-->
            <!--			<a class="switch_btn" id="switch_login" href="javascript:void(0);" tabindex="8">快速注册</a>-->
            <!--            <div class="switch_bottom" id="switch_bottom" style="position: absolute; width: 66px; left: 0px;"></div>-->
        </div>
    </div>


    <div class="web_qr_login" id="web_qr_login" style="display: block; height: 235px;">

        <!--登录-->
        <div class="web_login" id="web_login">

            <div class="login-box">
                <style>
                    .web_login .input-tips {
                        float: left;
                        margin-top: 10px;
                        width: 31px;
                        height: 42px;
                        font-size: 16px;
                        line-height: 42px;
                    }
                </style>
                <div class="login_form">
                    <form action="?act=rename" method="post" enctype="application/x-www-form-urlencoded"  name="loginform"  id="login_form" class="loginForm" >
                        <div style="    height: 45px;
    margin-bottom: 10px;
    position: relative;
    z-index: 3;
    text-align: center;
    line-height: 45px;
    font-size: 18px;
                        " id="pwdArea">
                           欢迎登录,请编辑一下您的个性昵称
                        </div>
                        <div style="display: none;
                        text-align: center;
    color: #FF9800;
    font-size: 16px;" id="tip">请输入昵称</div>
                        <div class="pwdArea" id="pwdArea">
                            <label class="input-tips" for="nickname"></label>

                            <div class="inputOuter" id="pArea">
                                <input type="nickname" id="nickname" name="nickname" class="inputstyle"/>
                                <input type="hidden" id="uid" value="<?=$userinfo['uid']?>" name="uid" class="inputstyle"/>
                            </div>
                        </div>

                        <div style="padding-left:60px;margin-top:20px;">

                            <div class="inputArea">
                                <input type="button" id="reg"  style="    margin-top: -4px;margin-left: 27px;" class="button_blue" value="进入直播间"/>
                            </div>
                        </div>
                    </form>
                </div>

            </div>

        </div>
        <!--登录end-->
    </div>


</div>
<script>

    $(document).ready(function() {

        $('#reg').click(function() {
            var nickname = $('#nickname').val();
            if(nickname.length <= 0){

                $('#tip').html('请输入昵称');
                $('#tip').show();
                return false;
            }

            if(nickname.length  < 2){
                $('#tip').html('昵称不能少于两个个字符');
                $('#tip').show();
                return false;
            }

            //判断是否含有特殊字符
            var containSpecial = RegExp(/[(\ )(\~)(\!)(\@)(\#)(\$)(\%)(\^)(\&)(\*)(\()(\))(\-)(\_)(\+)(\=)(\[)(\])(\{)(\})(\|)(\\)(\;)(\:)(\')(\")(\,)(\.)(\/)(\<)(\>)(\?)(\)]+/);
            if ( containSpecial.test(nickname) ){
                $('#tip').html('昵称不能含有特殊字符');
                $('#tip').show();
                return false;
            };

            if(nickname.length  == '<?=$userinfo['nickname']?>'){
                $('#tip').html('与账户名称相同,请重新修改');
                $('#tip').show();
                return false;
            }

            $('#login_form').submit();

//            top.alertAD();
        });


    });
</script>
</body>
</html>
